package se.webbzon.boltzmann.menu;

import java.awt.image.ImageObserver;

import se.webbzon.boltzmann.editor.Main;

public class MainPage extends MFlowPage {
	
	// The layout used for this page
	private final AbstractGameMenuLayout layout;

	/*============================================================
	Constructors
	============================================================*/
	
	public MainPage(ImageObserver observer, AbstractGameMenuLayout layout) {
		super(observer,layout.getPageLayout(),"Main");
		this.layout = layout;
		addItem(new PageLabel(observer,layout.getLabelLayout(),this));
		addRow(1.25);
		addItem(new PlayButton(layout.getButtonLayout()));
		addRow();
		addItem(new OptionsButton(layout.getButtonLayout()));
		addRow();
		addItem(new QuitButton(layout.getButtonLayout()));
	}
	
	/*============================================================
	Public Methods
	============================================================*/

	@Override public void onEnter(GameMenu menu) {}

	@Override public void onLeave(GameMenu menu) {}
	
	/*============================================================
	Private Classes
	============================================================*/
	
	private final class PlayButton extends MButton {

		public PlayButton(ButtonLayout layout) {
			super(getImageObserver(), layout, false, "Play");
		}

		@Override public void onClick(GameMenu menu) {
			menu.setPage(new PlayPage(getImageObserver(), layout,MainPage.this));
		}
		
	}
	
	private final class OptionsButton extends MButton {

		public OptionsButton(ButtonLayout layout) {
			super(getImageObserver(), layout, false, "Options");
		}

		@Override public void onClick(GameMenu menu) {
			menu.setPage(new OptionPage(getImageObserver(), layout,MainPage.this));
		}
		
	}
	
	private final class QuitButton extends MButton {

		public QuitButton(ButtonLayout layout) {
			super(getImageObserver(), layout, false, "Quit");
		}

		@Override public void onClick(GameMenu menu) {
			Main.exit();
		}
		
	}

}
